package com.shenghui.enterprise.base.controller;

import com.shenghui.enterprise.vo.Result;
import com.shenghui.enterprise.base.entity.BaseDataDictionaryDetail;
import com.shenghui.enterprise.base.entity.PageModel;
import com.shenghui.enterprise.base.service.IBaseDataDictionaryDetailService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Map;

/**
 * @Description: 字典子表 前端控制器
 * @Author houjh
 * @Email: happyxiaohou@gmail.com
 * @Date: 2020-06-01
 * @Copyright (c) 2020-2022 云南昇晖科技有限公司
 */
@RestController
@RequestMapping("/admin/baseDataDictionaryDetail" )
@Api(value = "字典子表接口",description = "用作字典子表演示")
public class BaseDataDictionaryDetailController {

    @Autowired
    private IBaseDataDictionaryDetailService baseDataDictionaryDetailService;

    /**
     * 数据字典详情列表
     * @return
     */
    @RequestMapping("/getDataDictionaryDetailList")
    public PageModel getDataDictionaryDetailList(@RequestParam Map map){
        try {
            return baseDataDictionaryDetailService.getDataDictionaryDetailList(map);
        } catch (Exception e) {
            e.printStackTrace();
            return new PageModel(0, null);
        }
    }

    /**
     * 添加数据字典详情
     * @return
     */
    @RequestMapping("/addDataDictionaryDetail")
    public Result addDataDictionaryDetail(BaseDataDictionaryDetail dataDictionaryDetail){
        try {
            return baseDataDictionaryDetailService.addDataDictionaryDetail(dataDictionaryDetail);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("添加失败");
        }
    }

    /**
     * 根据code获取字典表详情数据
     * @param code
     * @param codeTwo
     * @return
     */
    @RequestMapping("/getDicDetailByCode")
    public Result getDicDetailByCode(String code, String codeTwo){
        try {
            return baseDataDictionaryDetailService.getDicDetailByCode(code, codeTwo);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    /**
     * 根据id获取字典表详情数据
     * @return
     */
    @RequestMapping("/getDataDictionaryDetailById")
    public Result getDataDictionaryDetailById(String id){
        try {
            return baseDataDictionaryDetailService.getDataDictionaryDetailById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("查询失败");
        }
    }

    /**
     * 删除字典表详情数据
     * @return
     */
    @RequestMapping("/deleteDataDictionaryDetail")
    public Result deleteDataDictionaryDetail(String id){
        try {
            return baseDataDictionaryDetailService.deleteDataDictionaryDetail(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error("删除失败");
        }
    }

    /**
     * 根据父级字典code查询子字典列表
     * @param map
     * @return
     */
    @RequestMapping("/getDataDictionaryDetailListByParentCode")
    public Object getDataDictionaryDetailListByParentCode(@RequestParam Map map) {
        try {
            PageModel pageModel = baseDataDictionaryDetailService.getDataDictionaryDetailListByParentCode(map);
            return pageModel;
        } catch ( Exception e) {
            e.printStackTrace();
            return null;
        }
    }

}
